const { execSync } = require('child_process')
const { join } = require('path')

// Omit E, R, U for 'emoticon' 'remark-emoji' 'unist-util-visit-parents'
const AToZ = 'abcdfghijklmnopqstvwxyz'
  .split('')
  .map((char) => `--external:'${char}*'`)
  .join(' ')

// Omit M P for '@maiev/*' and '@perfkit/*'
const NamespaceAToZ = 'abcdefghijklnoqrstuvwxyz'
  .split('')
  .map((char) => `--external:'@${char}*'`)
  .join(' ')

// Make 'eslint xxx, rollup-xx, and RxJS as external'
const command = `${join(
  __dirname,
  '..',
  'node_modules',
  '.bin',
  'esbuild',
)} ./tools/cli/index.ts --bundle --platform=node --external:es* --external:ro* --external:rx* ${AToZ} ${NamespaceAToZ} --target=es2018 --outfile=./output/bundled-cli.js`

execSync(command, {
  stdio: 'inherit',
})
